//
//  UITextField+YS.m
//  Yueshi
//
//  Created by Northwan on 16/4/12.
//  Copyright © 2016年 悦食中国. All rights reserved.
//

#import "UITextField+YS.h"
#import <objc/runtime.h>

NSString * const YSTextFieldDidDeleteBackwardNotification = @"com.yueshichina.textfield.did.notification";

@implementation UITextField (YS)

+ (void)load {
    //交换2个方法中的IMP
    Method method1 = class_getInstanceMethod([self class], NSSelectorFromString(@"deleteBackward"));
    Method method2 = class_getInstanceMethod([self class], @selector(ys_deleteBackward));
    method_exchangeImplementations(method1, method2);
}

- (void)ys_deleteBackward {
    [self ys_deleteBackward];
    
    if ([self.delegate respondsToSelector:@selector(textFieldDidDeleteBackward:)])
    {
        id <YSTextFieldDelegate> delegate  = (id<YSTextFieldDelegate>)self.delegate;
        [delegate textFieldDidDeleteBackward:self];
    }
    
    [[NSNotificationCenter defaultCenter] postNotificationName:YSTextFieldDidDeleteBackwardNotification object:self];
}
@end